package com.forward.uploadapp.dialog;

import android.content.Context;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import com.forward.uploadapp.R;

/**
 * Created by ljh on 18-3-23.
 */

public class WarmDialog extends BaseDialog implements View.OnClickListener {
    private static WarmDialog mWarmDialog;
    private OnWarnDialogListener mWarnDialogListener;
    private TextView mTitle;
    private Button mCancel;
    private Button mSave;

    public static WarmDialog getInstance(Context context) {
        if (mWarmDialog == null) {
            mWarmDialog = new WarmDialog(context);
        }
        return mWarmDialog;
    }

    private WarmDialog(Context context) {
        super(context, R.style.DialogStyle);
        create();
    }

    @Override
    public int getLayoutId() {
        return R.layout.warn_dialog;
    }

    @Override
    public void initView() {
        mTitle = (TextView) findViewById(R.id.title);
        mCancel = (Button) findViewById(R.id.cancel);
        mSave = (Button) findViewById(R.id.save);
    }

    @Override
    public void initData() {

    }

    @Override
    public void initListener() {
        mCancel.setOnClickListener(this);
        mSave.setOnClickListener(this);
    }

    public void showDialog(String title, OnWarnDialogListener dialogListener) {
        mWarnDialogListener = dialogListener;
        mTitle.setText(title);
        show();
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.cancel:
                if (mWarnDialogListener != null) {
                    mWarnDialogListener.cancel(mWarmDialog);
                }
                break;
            case R.id.save:
                if (mWarnDialogListener != null) {
                    mWarnDialogListener.confirm(mWarmDialog);
                }
                break;
        }
    }
}